package cn.edu.sgu.www.mhxysy.controller.repository;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.repository.RolePackageService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "角色包裹管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/package", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class RolePackageController {

    private final RolePackageService rolePackageService;

    @Autowired
    public RolePackageController(RolePackageService rolePackageService) {
        this.rolePackageService = rolePackageService;
    }

    @ApiOperation("初始化角色的包裹")
    @RequestMapping(value = "/init", method = RequestMethod.POST)
    public JsonResult<Void> init(
            @ApiParam(name = "roleId", value = "角色ID", required = true)
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId) {
        rolePackageService.init(roleId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("解锁角色包裹")
    @RequestMapping(value = "/unlock", method = RequestMethod.POST)
    public JsonResult<Void> unlock(
            @ApiParam(name = "roleId", value = "角色ID", required = true)
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId) {
        rolePackageService.unlock(roleId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

}